<%@ page contentType="text/html; charset=utf-8" 
pageEncoding="utf-8" %>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%
	String DRV = "org.mariadb.jdbc.Driver";
	String URL = "jdbc:mariadb://localhost:3306/siestageek?user=siestageek&password=987654";
	String SQL = "select * from boardv4 where bdno = ?";
	String rSQL = "update boardv4 set reades=reades+1 where bdno=?";
	Connection conn = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
%>
<%
	String bdno = null;
	String title = null;
	String uid = null;
	String wdate = null;
	String reades = null;
	String contents = null;
%>
<%
	bdno = request.getParameter("bdno");
	// 조회할 본문글 번호가 입력되지 않으면
	// 자동으로 list.jsp로 이동시킴
	if (bdno==null) response.sendRedirect("list.jsp");
%>
<%
	try {
		Class.forName(DRV);
		conn = DriverManager.getConnection(URL);
		// 1. 조회수 증가
		pstmt = conn.prepareStatement(rSQL);
			pstmt.setString(1, bdno);
		pstmt.executeUpdate();
		if (pstmt != null) try { pstmt.close(); } catch (Exception e) { }
		// 2. 본문글 출력
		pstmt = conn.prepareStatement(SQL);
			pstmt.setString(1, bdno);
		rs = pstmt.executeQuery();
		
		if (rs.next()) {
			title = rs.getString("title");
			uid = rs.getString("uid");
			wdate = rs.getString("wdate");
			reades = rs.getString("reades");
			contents = rs.getString("contents");
		}else {
			// 입력한 본문글 번호가 boardv4에 
			// 존재하지 않으면 자동으로 list.jsp로 이동시킴
			response.sendRedirect("list.jsp");
		}
	} catch (Exception ex) {
		ex.printStackTrace();
	} finally {
		if (rs != null) try { rs.close(); } catch (Exception e) {}
		if (pstmt != null) try { pstmt.close(); } catch (Exception e) {}
		if (conn != null) try { conn.close(); } catch (Exception e) {}
	}
%>

		<style type="text/css">
			.contents { width: 550px; height: 250px;
				display: inline-block; 
				border: 1px solid gold;
				overflow: auto; }
			.dragup { vertical-align: top; }	
		</style>
		
		<div id="content">
			<h2>게시판 본문</h2>
			<div id="view">
				<div><label>제목</label><span> <%=title %> </span></div>
				<div><label>작성자</label><span><%=uid %></span></div>
				<div><label>작성일</label><span><%=wdate %> </span></div>
				<div><label>조회수</label><span><%=reades %> </span></div>
				<div><label class="dragup">본문</label>
				<span class="contents"><%=contents %></span></div>
				<div><label> </label><button type="button" id="updbtn">수정하기</button>
					<button type="button" id="delbtn">삭제하기</button> </div>
			</div>
		</div><!-- // content -->
		
		<script type="text/javascript">
			var deletebtn = document.getElementById("delbtn");
			deletebtn.onclick = function () { 
				if ( confirm('정말로 삭제하시겠습니까?') ) {
					location.href="?action=deleteok&bdno="+<%=bdno%>;
				}
			};
			var updatebtn = document.getElementById("updbtn");
			updatebtn.onclick = function() {
				location.href="?action=update&bdno=" + <%=bdno%>;
			};
		</script>
		




